package main

import (
	"context"
	"fmt"
	"github.com/micro/go-micro/v2"
	"github.com/micro/go-micro/v2/registry"
	"github.com/micro/go-plugins/registry/consul/v2"
	"log"
	"microdemo/proto"
)

func main() {
	// windows中使用默认的mdns服务发现有问题，目前还未解决
	reg := consul.NewRegistry(func(options *registry.Options) {
		options.Addrs = []string{"127.0.0.1:8500"}
	})
	// 实例化
	srv := micro.NewService(micro.Name("user.client"), micro.Registry(reg))
	// 初始化
	srv.Init()
	// 调用其他服务
	user := proto.NewUserService("user", srv.Client())
	res, err := user.Register(context.TODO(), &proto.RegisterRequest{
		Username: "18232587802",
		Password: "123456",
		Nickname: "王小明",
	})
	if err != nil {
		log.Fatalln("调用服务出错", err)
	}
	fmt.Println(res)
}
